package org.lc.cmd.impl.bridge;

import org.jline.reader.LineReader;
import org.jline.utils.AttributedString;
import org.lc.cmd.impl.TerminalRunner;

public class JLineHttpClientBridge extends HttpClientBridge {
    protected TerminalRunner terminalRunner;

    public JLineHttpClientBridge(String serverUrl, TerminalRunner terminalRunner) {
        super(serverUrl);
        this.terminalRunner = terminalRunner;
    }

    @Override
    public String readLine(String prompt) {
        return terminalRunner.getReader().readLine(prompt);
    }

    @Override
    public void write(AttributedString str, boolean above) {
        LineReader reader = terminalRunner.getReader();
        if (above) {
            reader.printAbove(str);
        } else {
            str.print(reader.getTerminal());
        }
    }
}
